diff --git a/web/pgadmin/about/static/js/about.js b/web/pgadmin/about/static/js/about.js index c692ae1c..1e72c917 100644 --- a/web/pgadmin/about/static/js/about.js +++ b/web/pgadmin/about/static/js/about.js @@ -1,13 +1,13 @@ define( ['jquery', 'alertify', 'sources/pgadmin', 'underscore.string', 'sources/gettext', - 'sources/url_for' + 'sources/url_for', ], function($, alertify, pgAdmin, S, gettext, url_for) { pgAdmin = pgAdmin || window.pgAdmin || {}; /* Return back, this has been called more than once */ if (pgAdmin.About) - return; + return; pgAdmin.About = { about_show: function() { @@ -20,14 +20,14 @@ define( }, setup: function() { return { - buttons:[{ text: gettext("OK"), key: 27, className: "btn btn-primary" }], + buttons:[{ text: gettext('OK'), key: 27, className: 'btn btn-primary' }], options: { modal: false, resizable: true, maximizable: true, pinnable: false, - closableByDimmer: false - } + closableByDimmer: false, + }, }; }, build: function() { @@ -35,19 +35,18 @@ define( }, prepare:function() { this.setContent(this.message); - } + }, }; }); } - var content = ''; $.get(url_for('about.index'), function(data) { alertify.aboutDialog( - S(gettext("About %s")).sprintf(pgAdmin.Browser.utils.app_name).value(), data + S(gettext('About %s')).sprintf(pgAdmin.Browser.utils.app_name).value(), data ).resizeTo(800, 450); }); - } + }, }; return pgAdmin.About; diff --git a/web/pgadmin/dashboard/static/js/dashboard.js b/web/pgadmin/dashboard/static/js/dashboard.js index 0da32f60..6fcef0fb 100644 --- a/web/pgadmin/dashboard/static/js/dashboard.js +++ b/web/pgadmin/dashboard/static/js/dashboard.js @@ -1,14 +1,15 @@ define('pgadmin.dashboard', [ - 'sources/url_for', 'sources/gettext', 'require', 'jquery', 'underscore', - 'sources/pgadmin', 'backbone', 'backgrid', 'flotr2', - 'pgadmin.alertifyjs', 'backgrid.filter', - 'pgadmin.browser', 'bootstrap', 'wcdocker' - ], -function(url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr, - alertify) { - - var wcDocker = window.wcDocker, - pgBrowser = pgAdmin.Browser; + 'sources/url_for', 'sources/gettext', 'require', 'jquery', 'underscore', + 'sources/pgadmin', 'backbone', 'backgrid', 'flotr2', + 'pgadmin.alertifyjs', 'pgadmin.backform', 'backgrid.filter', + 'pgadmin.browser', 'bootstrap', 'wcdocker', +], function( + url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr, + Alertify, Backform +) { + + pgAdmin.Browser = pgAdmin.Browser || {}; + var pgBrowser = pgAdmin.Browser; /* Return back, this has been called more than once */ if (pgAdmin.Dashboard) @@ -24,102 +25,103 @@ function(url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr, // Custom BackGrid cell, Responsible for cancelling active sessions var customDashboardActionCell = Backgrid.Extension.DeleteCell.extend({ - render: function () { - this.$el.empty(); - var self = this, - cell_action = self.column.get('cell_action'); - // if cancel query button then - if (cell_action === 'cancel') { - this.$el.html( - "" - ); - } else { - this.$el.html( - "" - ); - } - this.delegateEvents(); - return this; - }, - deleteRow: function(e) { - var self = this, - title, txtConfirm, txtSuccess, txtError, action_url, - cell_action = self.column.get('cell_action'); - - e.preventDefault(); - - var canDeleteRow = Backgrid.callByNeed( - self.column.get('canDeleteRow'), self.column, self.model - ); - // If we are not allowed to cancel the query, return from here - if(!canDeleteRow) - return; - - // This will refresh the grid - var refresh_grid = function() { - if(is_server_dashboard) { - $('#btn_server_activity_refresh').click(); - } else if(is_database_dashboard) { - $('#btn_database_activity_refresh').click(); - } - }; - - if (cell_action === 'cancel') { - title = gettext('Cancel Active Query?'); - txtConfirm = gettext('Are you sure you wish to cancel the active query?'); - txtSuccess = gettext('Active query cancelled successfully.') - txtError = gettext('An error occurred whilst cancelling the active query.') - action_url = cancel_query_url + self.model.get('pid') - } else { - title = gettext('Terminate Session?'); - txtConfirm = gettext('Are you sure you wish to terminate the session?'); - txtSuccess = gettext('Session terminated successfully.') - txtError = gettext('An error occurred whilst terminating the active query.') - action_url = terminate_session_url + self.model.get('pid') - } + render: function() { + this.$el.empty(); + var self = this, + cell_action = self.column.get('cell_action'); + // if cancel query button then + if (cell_action === 'cancel') { + this.$el.html( + '' + ); + } else { + this.$el.html( + '' + ); + } + this.delegateEvents(); + return this; + }, + deleteRow: function(e) { + var self = this, + title, txtConfirm, txtSuccess, txtError, action_url, + cell_action = self.column.get('cell_action'); + + e.preventDefault(); + + var canDeleteRow = Backgrid.callByNeed( + self.column.get('canDeleteRow'), self.column, self.model + ); + // If we are not allowed to cancel the query, return from here + if (!canDeleteRow) + return; + + // This will refresh the grid + var refresh_grid = function() { + if (is_server_dashboard) { + $('#btn_server_activity_refresh').click(); + } else if (is_database_dashboard) { + $('#btn_database_activity_refresh').click(); + } + }; + + if (cell_action === 'cancel') { + title = gettext('Cancel Active Query?'); + txtConfirm = gettext('Are you sure you wish to cancel the active query?'); + txtSuccess = gettext('Active query cancelled successfully.'); + txtError = gettext('An error occurred whilst cancelling the active query.'); + action_url = cancel_query_url + self.model.get('pid'); + } else { + title = gettext('Terminate Session?'); + txtConfirm = gettext('Are you sure you wish to terminate the session?'); + txtSuccess = gettext('Session terminated successfully.'); + txtError = gettext('An error occurred whilst terminating the active query.'); + action_url = terminate_session_url + self.model.get('pid'); + } - alertify.confirm( - title, - txtConfirm, - function(evt) { - $.ajax({ - url: action_url, - type:'DELETE', - success: function(res) { - if (res == gettext('Success')) { - alertify.success(txtSuccess); - refresh_grid(); - } else { - alertify.error(txtError); - } - }, - error: function(xhr, status, error) { - try { - var err = $.parseJSON(xhr.responseText); - if (err.success == 0) { - alertify.error(err.errormsg); - } - } catch (e) {} + Alertify.confirm( + title, txtConfirm, + function() { + $.ajax({ + url: action_url, + type: 'DELETE', + success: function(res) { + if (res == gettext('Success')) { + Alertify.success(txtSuccess); + refresh_grid(); + } else { + Alertify.error(txtError); + } + }, + error: function(xhr) { + try { + var err = $.parseJSON(xhr.responseText); + if (err.success == 0) { + Alertify.error(err.errormsg); } - }); + } catch (e) { + console.warn(e.stack || e); + } }, - function(evt) { - return true; - } - ); + }); + }, + function() { + return true; } + ); + }, }); // Subnode Cell, which will display subnode control var SessionDetailsCell = Backgrid.Extension.ObjectCell.extend({ - enterEditMode: function () { + enterEditMode: function() { // Notify that we are about to enter in edit mode for current cell. - this.model.trigger("enteringEditMode", [this]); + this.model.trigger('enteringEditMode', [this]); Backgrid.Cell.prototype.enterEditMode.apply(this, arguments); /* Make sure - we listen to the click event */ @@ -128,1159 +130,1204 @@ function(url_for, gettext, r, $, _, pgAdmin, Backbone, Backgrid, Flotr, if (editable) { this.$el.html( - "" - ); + '' + ); this.model.trigger( - "pg-sub-node:opened", this.model, this - ); + 'pg-sub-node:opened', this.model, this + ); } }, - render: function(){ - this.$el.empty(); - this.$el.html( - "" - ); - this.delegateEvents(); - if (this.grabFocus) - this.$el.focus(); - return this; - } + render: function() { + this.$el.empty(); + this.$el.html( + '' + ); + this.delegateEvents(); + if (this.grabFocus) + this.$el.focus(); + return this; + }, }); // Subnode Model var ActiveQueryDetailsModel = Backbone.Model.extend({ defaults: { - version: null /* Postgres version */ + version: null, + /* Postgres version */ }, schema: [{ - id: 'backend_type', label: gettext('Backend type'), - type: 'text', editable: true, disabled: true, + id: 'backend_type', + label: gettext('Backend type'), + type: 'text', + editable: true, + disabled: true, group: gettext('Details'), - visible: function(m) { + visible: function() { return this.version >= 100000; - } - },{ - id: 'query_start', label: gettext('Query started at'), - type: 'text', editable: false, disabled: true, - group: gettext('Details') - },{ - id: 'state_change', label: gettext('Last state changed at'), - type: 'text', editable: true, disabled: true, - group: gettext('Details') - },{ - id: 'query', label: gettext('SQL'), - type: 'text', editable: true, disabled: true, + }, + }, { + id: 'query_start', + label: gettext('Query started at'), + type: 'text', + editable: false, + disabled: true, + group: gettext('Details'), + }, { + id: 'state_change', + label: gettext('Last state changed at'), + type: 'text', + editable: true, + disabled: true, + group: gettext('Details'), + }, { + id: 'query', + label: gettext('SQL'), + type: 'text', + editable: true, + disabled: true, control: Backform.SqlFieldControl, - group: gettext('Details') - }] + group: gettext('Details'), + }], }); pgAdmin.Dashboard = { - init: function() { - if (this.initialized) - return; - - this.initialized = true; - - // Bind the Dashboard object with the 'object_selected' function - var selected = this.object_selected.bind(this); - var disconnected = this.object_disconnected.bind(this); - - // Listen for selection of any of object - pgBrowser.Events.on('pgadmin-browser:tree:selected', selected); - - // Listen for server disconnected event - pgBrowser.Events.on('pgadmin:server:disconnect', disconnected); - - // Load the default welcome dashboard - var url = url_for('dashboard.index'); - - var dashboardPanel = pgBrowser.panels['dashboard'].panel; - if (dashboardPanel) { - var div = dashboardPanel.layout().scene().find('.pg-panel-content'); - - if (div) { - $.ajax({ - url: url, - type: "GET", - dataType: "html", - success: function (data) { - $(div).html(data); - }, - error: function (xhr, status) { - $(div).html( - '
' - ); - } - }); - - // Cache the current IDs for next time - $(dashboardPanel).data('sid', -1) - $(dashboardPanel).data('did', -1) - } - } - }, - - // Handle Server Disconnect - object_disconnected: function(obj) { - this.object_selected(obj.item, obj.data, pgBrowser.Nodes[obj.data._type]); - }, + init: function() { + if (this.initialized) + return; - // Handle treeview clicks - object_selected: function(item, itemData, node) { - if (itemData && itemData._type && dashboardVisible) { - var treeHierarchy = node.getTreeNodeHierarchy(item), - url = url_for('dashboard.index'), - sid = -1, did = -1, b = pgAdmin.Browser, - m = b && b.Nodes[itemData._type]; - - cancel_query_url = url_for('dashboard.index') + 'cancel_query/'; - terminate_session_url = url_for('dashboard.index') + 'terminate_session/'; - - // Check if user is super user - var server = treeHierarchy['server']; - maintenance_database = (server && server.db) || null; - - if(server && server.user && server.user.is_superuser) { - is_super_user = true; - } else { - is_super_user = false; - // Set current user - current_user = (server && server.user) ? server.user.name : null; - } + this.initialized = true; - if (m && m.dashboard) { - if (_.isFunction(m.dashboard)) { - url = m.dashboard.apply( - item, itemData, node, treeHierarchy - ); - } else { - url = m.dashboard; - } - } else { - if ('database' in treeHierarchy) { - sid = treeHierarchy.server._id; - did = treeHierarchy.database._id; - is_server_dashboard = false; - is_database_dashboard = true; - url += sid + '/' + did; - cancel_query_url += sid + '/' + did + '/'; - terminate_session_url += sid + '/' + did + '/'; - } else if ('server' in treeHierarchy) { - sid = treeHierarchy.server._id; - is_server_dashboard = true; - is_database_dashboard = false; - url += sid; - cancel_query_url += sid + '/'; - terminate_session_url += sid + '/'; - } - } + // Bind the Dashboard object with the 'object_selected' function + var selected = this.object_selected.bind(this); + var disconnected = this.object_disconnected.bind(this); - var dashboardPanel = pgBrowser.panels['dashboard'].panel; - if (dashboardPanel) { - var div = dashboardPanel.layout().scene().find( - '.pg-panel-content' - ); - - if (div) { - if (itemData.connected || _.isUndefined(itemData.connected)) { - // Avoid unnecessary reloads - if (url != $(dashboardPanel).data('dashboard_url') || - (url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false )) { - // Clear out everything so any existing timers die off - $(div).empty(); - - $.ajax({ - url: url, - type: "GET", - dataType: "html", - success: function (data) { - $(div).html(data); - }, - error: function (xhr, status) { - $(div).html( - '' - ); - } - }); - $(dashboardPanel).data('server_status', true); - } - - } - else { - $(div).empty(); - $(div).html( - '' - ); - $(dashboardPanel).data('server_status', false); - } - // Cache the current IDs for next time - $(dashboardPanel).data('dashboard_url', url); - - } - } - } - }, + // Listen for selection of any of object + pgBrowser.Events.on('pgadmin-browser:tree:selected', selected); - // Render a chart - render_chart: function(container, data, dataset, sid, did, url, options, counter, refresh) { + // Listen for server disconnected event + pgBrowser.Events.on('pgadmin:server:disconnect', disconnected); - // Data format: - // [ - // { data: [[0, y0], [1, y1]...], label: 'Label 1', [options] }, - // { data: [[0, y0], [1, y1]...], label: 'Label 2', [options] }, - // { data: [[0, y0], [1, y1]...], label: 'Label 3', [options] } - // ] + // Load the default welcome dashboard + var url = url_for('dashboard.index'); - if (!dashboardVisible) - return; + var dashboardPanel = pgBrowser.panels['dashboard'].panel; + if (dashboardPanel) { + var div = dashboardPanel.layout().scene().find('.pg-panel-content'); - var y = 0; - if (dataset.length == 0) { - if (counter == true) - { - // Have we stashed initial values? - if (_.isUndefined($(container).data('counter_previous_vals'))) { - $(container).data('counter_previous_vals', data[0]) - } else { - // Create the initial data structure - for (var x in data[0]) { - dataset.push({ 'data': [[0, data[0][x] - $(container).data('counter_previous_vals')[x]]], 'label': x }); - } - } - } else { - // Create the initial data structure - for (var x in data[0]) { - dataset.push({ 'data': [[0, data[0][x]]], 'label': x }); - } - } - } else { - for (var x in data[0]) { - // Push new values onto the existing data structure - // If this is a counter stat, we need to subtract the previous value - if (counter == false) { - dataset[y]['data'].unshift([0, data[0][x]]); - } else { - // Store the current value, minus the previous one we stashed. - // It's possible the tab has been reloaded, in which case out previous values are gone - if (_.isUndefined($(container).data('counter_previous_vals'))) - return - - dataset[y]['data'].unshift([0, data[0][x] - $(container).data('counter_previous_vals')[x]]); - } - - // Reset the time index to get a proper scrolling display - for (var z = 0; z < dataset[y]['data'].length; z++) { - dataset[y]['data'][z][0] = z; - } - - y++; - } - $(container).data('counter_previous_vals', data[0]) - } + if (div) { + $.ajax({ + url: url, + type: 'GET', + dataType: 'html', + success: function(data) { + $(div).html(data); + }, + error: function() { + $(div).html( + '' + ); + }, + }); - // Remove uneeded elements - for (x = 0; x < dataset.length; x++) { - // Remove old data points - if (dataset[x]['data'].length > 101) { - dataset[x]['data'].pop(); - } - } + // Cache the current IDs for next time + $(dashboardPanel).data('sid', -1); + $(dashboardPanel).data('did', -1); + } + } + }, - // Draw Graph, if the container still exists and has a size - var dashboardPanel = pgBrowser.panels['dashboard'].panel; - var div = dashboardPanel.layout().scene().find('.pg-panel-content'); - if ($(div).find(container).length) { // Exists? - if (container.clientHeight > 0 && container.clientWidth > 0) { // Not hidden? - Flotr.draw(container, dataset, options); - } - } else { - return; - } + // Handle Server Disconnect + object_disconnected: function(obj) { + this.object_selected(obj.item, obj.data, pgBrowser.Nodes[obj.data._type]); + }, - // Animate - var setTimeoutFunc = function () { - var path = url + sid; - if (did != -1) { - path += '/' + did; - } - $.ajax({ - url: path, - type: "GET", - dataType: "html", - success: function (resp) { - $(container).removeClass('graph-error') - data = JSON.parse(resp); - pgAdmin.Dashboard.render_chart(container, data, dataset, sid, did, url, options, counter, refresh); - }, - error: function (xhr, status, msg) { - var err = $.parseJSON(xhr.responseText), - msg = err.errormsg, - cls; - // If we get a 428, it means the server isn't connected - if (xhr.status == 428) { - if (_.isUndefined(msg) || _.isNull(msg)) { - msg = gettext('Please connect to the selected server to view the graph.'); - } - cls = 'info'; - } else { - msg = gettext('An error occurred whilst rendering the graph.'); - cls = 'danger'; - } - - $(container).addClass('graph-error'); - $(container).html( - '' - ); - - // Try again... - if (container.clientHeight > 0 && container.clientWidth > 0) { - setTimeout(setTimeoutFunc, refresh * 1000); - } - }, - }); - }; + // Handle treeview clicks + object_selected: function(item, itemData, node) { + if (itemData && itemData._type && dashboardVisible) { + var treeHierarchy = node.getTreeNodeHierarchy(item), + url = url_for('dashboard.index'), + sid = -1, + did = -1, + b = pgAdmin.Browser, + m = b && b.Nodes[itemData._type]; + + cancel_query_url = url_for('dashboard.index') + 'cancel_query/'; + terminate_session_url = url_for('dashboard.index') + 'terminate_session/'; + + // Check if user is super user + var server = treeHierarchy['server']; + maintenance_database = (server && server.db) || null; + + if (server && server.user && server.user.is_superuser) { + is_super_user = true; + } else { + is_super_user = false; + // Set current user + current_user = (server && server.user) ? server.user.name : null; + } - setTimeout(setTimeoutFunc, refresh * 1000); - }, + if (m && m.dashboard) { + if (_.isFunction(m.dashboard)) { + url = m.dashboard.apply( + item, itemData, node, treeHierarchy + ); + } else { + url = m.dashboard; + } + } else { + if ('database' in treeHierarchy) { + sid = treeHierarchy.server._id; + did = treeHierarchy.database._id; + is_server_dashboard = false; + is_database_dashboard = true; + url += sid + '/' + did; + cancel_query_url += sid + '/' + did + '/'; + terminate_session_url += sid + '/' + did + '/'; + } else if ('server' in treeHierarchy) { + sid = treeHierarchy.server._id; + is_server_dashboard = true; + is_database_dashboard = false; + url += sid; + cancel_query_url += sid + '/'; + terminate_session_url += sid + '/'; + } + } - // Handler function to support the "Add Server" link - add_new_server: function() { - if (pgBrowser && pgBrowser.tree) { - var i = pgBrowser.tree.selected().length != 0 ? - pgBrowser.tree.selected() : - pgBrowser.tree.first(null, false), - serverModule = r('pgadmin.node.server'), - itemData = pgBrowser.tree.itemData(i); - - while (itemData && itemData._type != "server_group") { - i = pgBrowser.tree.next(i); - itemData = pgBrowser.tree.itemData(i); - } + var dashboardPanel = pgBrowser.panels['dashboard'].panel; + if (dashboardPanel) { + var div = dashboardPanel.layout().scene().find( + '.pg-panel-content' + ); - if (!itemData) { - return; - } + if (div) { + if (itemData.connected || _.isUndefined(itemData.connected)) { + // Avoid unnecessary reloads + if (url != $(dashboardPanel).data('dashboard_url') || + (url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false)) { + // Clear out everything so any existing timers die off + $(div).empty(); - if (serverModule) { - serverModule.callbacks.show_obj_properties.apply( - serverModule, [{action: 'create'}, i] + $.ajax({ + url: url, + type: 'GET', + dataType: 'html', + success: function(data) { + $(div).html(data); + }, + error: function() { + $(div).html( + '' ); - } - } - }, - - // Render a grid - render_grid: function(container, sid, did, url, columns) { - var Datum = Backbone.Model.extend({}); + }, + }); + $(dashboardPanel).data('server_status', true); + } - var path = url + sid; - if (did != -1) { - path += '/' + did; + } else { + $(div).empty(); + $(div).html( + '' + ); + $(dashboardPanel).data('server_status', false); } + // Cache the current IDs for next time + $(dashboardPanel).data('dashboard_url', url); - var Data = Backbone.Collection.extend({ - model: Datum, - url: path, - mode: "client" - }); - - var data = new Data(); - - // Set up the grid - var grid = new Backgrid.Grid({ - columns: columns, - collection: data, - className: "backgrid table-bordered presentation table backgrid-striped" - }); - - // Render the grid - $(container).append(grid.render().el) + } + } + } + }, - // Initialize a client-side filter to filter on the client - // mode pageable collection's cache. - var filter = new Backgrid.Extension.ClientSideFilter({ - collection: data + // Render a chart + render_chart: function( + container, data, dataset, sid, did, url, options, counter, refresh + ) { + + // Data format: + // [ + // { data: [[0, y0], [1, y1]...], label: 'Label 1', [options] }, + // { data: [[0, y0], [1, y1]...], label: 'Label 2', [options] }, + // { data: [[0, y0], [1, y1]...], label: 'Label 3', [options] } + // ] + + if (!dashboardVisible) + return; + + var y = 0, + x; + if (dataset.length == 0) { + if (counter == true) { + // Have we stashed initial values? + if (_.isUndefined($(container).data('counter_previous_vals'))) { + $(container).data('counter_previous_vals', data[0]); + } else { + // Create the initial data structure + for (x in data[0]) { + dataset.push({ + 'data': [ + [0, data[0][x] - $(container).data('counter_previous_vals')[x]], + ], + 'label': x, + }); + } + } + } else { + // Create the initial data structure + for (x in data[0]) { + dataset.push({ + 'data': [ + [0, data[0][x]], + ], + 'label': x, }); + } + } + } else { + for (x in data[0]) { + // Push new values onto the existing data structure + // If this is a counter stat, we need to subtract the previous value + if (counter == false) { + dataset[y]['data'].unshift([0, data[0][x]]); + } else { + // Store the current value, minus the previous one we stashed. + // It's possible the tab has been reloaded, in which case out previous values are gone + if (_.isUndefined($(container).data('counter_previous_vals'))) + return; - // Render the filter - $('#' + container.id + '_filter').before(filter.render().el); - - // Add some space to the filter and move it to the right - $(filter.el).css({float: "right", margin: "5px", "margin-right": "2px", "margin-top": "3px"}); - - // Stash objects for future use - $(container).data('data', data); - $(container).data('grid', grid); - $(container).data('filter', filter); - }, - - // Render the data in a grid - render_grid_data: function(container) { - var data = $(container).data('data'), - grid = $(container).data('grid'), - filter = $(container).data('filter'); + dataset[y]['data'].unshift([0, data[0][x] - $(container).data('counter_previous_vals')[x]]); + } - if(_.isUndefined(data)){ - return null; - } + // Reset the time index to get a proper scrolling display + for (var z = 0; z < dataset[y]['data'].length; z++) { + dataset[y]['data'][z][0] = z; + } - data.fetch({ - reset: true, - success: function() { - // If we're showing an error, remove it, and replace the grid & filter - if ($(container).hasClass('grid-error')) { - $(container).removeClass('grid-error'); - $(container).html(grid.render().el) - $(filter.el).show(); - } - - // Re-apply search criteria - filter.search(); - }, - error: function(model, xhr, options) { - var err = $.parseJSON(xhr.responseText), - msg = err.errormsg, - cls; - // If we get a 428, it means the server isn't connected - if (xhr.status == 428) { - if (_.isUndefined(msg) || _.isNull(msg)) { - msg = gettext('Please connect to the selected server to view the table.'); - } - cls = 'info'; - } else { - msg = gettext('An error occurred whilst rendering the table.'); - cls = 'danger'; - } - - // Replace the content with the error, if not already present. Always update the message - if (!$(container).hasClass('grid-error')) { - $(filter.el).hide(); - $(container).addClass('grid-error'); - } - - $(container).html( - '' - ); + y++; + } + $(container).data('counter_previous_vals', data[0]); + } - // Try again - setTimeout(function() { - pgAdmin.Dashboard.render_grid_data(container, data); - }, 5000) - } - }); - }, + // Remove uneeded elements + for (x = 0; x < dataset.length; x++) { + // Remove old data points + if (dataset[x]['data'].length > 101) { + dataset[x]['data'].pop(); + } + } - // Rock n' roll on the server dashboard - init_server_dashboard: function(sid, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { - var div_sessions = $('.dashboard-container').find('#graph-sessions')[0]; - var div_tps = $('.dashboard-container').find('#graph-tps')[0]; - var div_ti = $('.dashboard-container').find('#graph-ti')[0]; - var div_to = $('.dashboard-container').find('#graph-to')[0]; - var div_bio = $('.dashboard-container').find('#graph-bio')[0]; - var div_server_activity = $('.dashboard-container').find('#server_activity'); - var div_server_locks = $('.dashboard-container').find('#server_locks'); - var div_server_prepared = $('.dashboard-container').find('#server_prepared'); - var div_server_config = $('.dashboard-container').find('#server_config'); - var dataset_sessions = []; - var data_sessions = []; - var dataset_tps = []; - var data_tps = []; - var dataset_ti = []; - var data_ti = []; - var dataset_to = []; - var data_to = []; - var dataset_bio = []; - var data_bio = []; - - // Fake DB ID - var did = -1; - - var options_line = { - parseFloat: false, - xaxis: { - min: 100, - max: 0, - autoscale: 0 - }, - yaxis : { - autoscale: 1 - }, - legend : { - position : 'nw', - backgroundColor : '#D2E8FF' - } - } + // Draw Graph, if the container still exists and has a size + var dashboardPanel = pgBrowser.panels['dashboard'].panel; + var div = dashboardPanel.layout().scene().find('.pg-panel-content'); + if ($(div).find(container).length) { // Exists? + if (container.clientHeight > 0 && container.clientWidth > 0) { // Not hidden? + Flotr.draw(container, dataset, options); + } + } else { + return; + } - var server_activity_columns = [{ - name: "pid", - label: gettext('PID'), - editable: false, - cell: "string" - }, { - name: "datname", - label: gettext('Database'), - editable: false, - cell: "string" - }, { - name: "usename", - label: gettext('User'), - editable: false, - cell: "string" - }, { - name: "application_name", - label: gettext('Application'), - editable: false, - cell: "string" - }, { - name: "client_addr", - label: gettext('Client'), - editable: false, - cell: "string" - }, { - name: "backend_start", - label: gettext('Backend start'), - editable: false, - cell: "string" - }, { - name: "state", - label: gettext('State'), - editable: false, - cell: "string" - }]; - - if (version < 90600) { - server_activity_columns = server_activity_columns.concat( - [{ - name: "waiting", - label: gettext('Waiting?'), - editable: false, - cell: "string" - }]); + // Animate + var setTimeoutFunc = function() { + var path = url + sid; + if (did != -1) { + path += '/' + did; + } + $.ajax({ + url: path, + type: 'GET', + dataType: 'html', + success: function(resp) { + $(container).removeClass('graph-error'); + data = JSON.parse(resp); + pgAdmin.Dashboard.render_chart(container, data, dataset, sid, did, url, options, counter, refresh); + }, + error: function(xhr) { + var err = $.parseJSON(xhr.responseText), + msg = err.errormsg, + cls; + // If we get a 428, it means the server isn't connected + if (xhr.status == 428) { + if (_.isUndefined(msg) || _.isNull(msg)) { + msg = gettext('Please connect to the selected server to view the graph.'); + } + cls = 'info'; } else { - server_activity_columns = server_activity_columns.concat( - [{ - name: "wait_event", - label: gettext('Wait Event'), - editable: false, - cell: "string" - },{ - name: "blocking_pids", - label: gettext('Blocking PIDs'), - editable: false, - cell: "string" - }]); + msg = gettext('An error occurred whilst rendering the graph.'); + cls = 'danger'; } - var newActiveQueryDetailsModel = new ActiveQueryDetailsModel(); - - var subNodeFieldsModel = Backform.generateViewSchema( - null, newActiveQueryDetailsModel, 'create', null, null, true - ); - - // Add version to each field - _.each(subNodeFieldsModel[0].fields, function(obj) { - obj['version'] = version; - }); - - // Add cancel active query button - server_activity_columns.unshift({ - name: "pg-backform-expand", label: "", - cell: SessionDetailsCell, - cell_priority: -1, - postgres_version: version, - schema: subNodeFieldsModel - }); - - // Add cancel active query button - server_activity_columns.unshift({ - name: "pg-backform-delete", label: "", - cell: customDashboardActionCell, - cell_action: 'cancel', - editable: false, cell_priority: -1, - canDeleteRow: pgAdmin.Dashboard.can_take_action, - postgres_version: version - }); - - server_activity_columns.unshift({ - name: "pg-backform-delete", label: "", - cell: customDashboardActionCell, - cell_action: 'terminate', - editable: false, cell_priority: -1, - canDeleteRow: pgAdmin.Dashboard.can_take_action, - postgres_version: version - }); - - var server_locks_columns = [{ - name: "pid", - label: gettext('PID'), - editable: false, - cell: "string" - }, { - name: "datname", - label: gettext('Database'), - editable: false, - cell: "string" - }, { - name: "locktype", - label: gettext('Lock type'), - editable: false, - cell: "string" - }, { - name: "relation", - label: gettext('Target relation'), - editable: false, - cell: "string" - }, { - name: "page", - label: gettext('Page'), - editable: false, - cell: "string" - }, { - name: "tuple", - label: gettext('Tuple'), - editable: false, - cell: "string" - }, { - name: "virtualxid", - label: gettext('vXID (target)'), - editable: false, - cell: "string" - }, { - name: "transactionid", - label: gettext('XID (target)'), - editable: false, - cell: "string" - },{ - name: "classid", - label: gettext('Class'), - editable: false, - cell: "string" - },{ - name: "objid", - label: gettext('Object ID'), - editable: false, - cell: "string" - },{ - name: "virtualtransaction", - label: gettext('vXID (owner)'), - editable: false, - cell: "string" - },{ - name: "mode", - label: gettext('Mode'), - editable: false, - cell: "string" - },{ - name: "granted", - label: gettext('Granted?'), - editable: false, - cell: "string" - }]; - - var server_prepared_columns = [{ - name: "git", - label: gettext('Name'), - editable: false, - cell: "string" - }, { - name: "database", - label: gettext('Database'), - editable: false, - cell: "string" - }, { - name: "Owner", - label: gettext('Owner'), - editable: false, - cell: "string" - }, { - name: "transaction", - label: gettext('XID'), - editable: false, - cell: "string" - }, { - name: "prepared", - label: gettext('Prepared at'), - editable: false, - cell: "string" - }]; - - var server_config_columns = [{ - name: "name", - label: gettext('Name'), - editable: false, - cell: "string" - }, { - name: "category", - label: gettext('Category'), - editable: false, - cell: "string" - }, { - name: "setting", - label: gettext('Setting'), - editable: false, - cell: "string" - }, { - name: "unit", - label: gettext('Unit'), - editable: false, - cell: "string" - }, { - name: "short_desc", - label: gettext('Description'), - editable: false, - cell: "string" - }]; - - // Render the graphs - pgAdmin.Dashboard.render_chart( - div_sessions, data_sessions, dataset_sessions, sid, did, - url_for('dashboard.session_stats'), options_line, false, - session_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_tps, data_tps, dataset_tps, sid, did, - url_for('dashboard.tps_stats'), options_line, true, - tps_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_ti, data_ti, dataset_ti, sid, did, - url_for('dashboard.ti_stats'), options_line, true, - ti_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_to, data_to, dataset_to, sid, did, - url_for('dashboard.to_stats'), options_line, true, - to_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_bio, data_bio, dataset_bio, sid, did, - url_for('dashboard.bio_stats'), options_line, true, - bio_stats_refresh + $(container).addClass('graph-error'); + $(container).html( + '' ); - // To align subnode controls properly - $(div_server_activity).addClass('pg-el-container'); - $(div_server_activity).attr('el', 'sm'); + // Try again... + if (container.clientHeight > 0 && container.clientWidth > 0) { + setTimeout(setTimeoutFunc, refresh * 1000); + } + }, + }); + }; - // Render the tabs, but only get data for the activity tab for now - pgAdmin.Dashboard.render_grid( - div_server_activity, sid, did, - url_for('dashboard.activity'), server_activity_columns - ); - pgAdmin.Dashboard.render_grid( - div_server_locks, sid, did, url_for('dashboard.locks'), - server_locks_columns - ); - pgAdmin.Dashboard.render_grid( - div_server_prepared, sid, did, url_for('dashboard.prepared'), - server_prepared_columns - ); - pgAdmin.Dashboard.render_grid( - div_server_config, sid, did, url_for('dashboard.config'), - server_config_columns - ); + setTimeout(setTimeoutFunc, refresh * 1000); + }, - pgAdmin.Dashboard.render_grid_data(div_server_activity); + // Handler function to support the "Add Server" link + add_new_server: function() { + if (pgBrowser && pgBrowser.tree) { + var i = pgBrowser.tree.selected().length != 0 ? + pgBrowser.tree.selected() : + pgBrowser.tree.first(null, false), + serverModule = require('pgadmin.node.server'), + itemData = pgBrowser.tree.itemData(i); + + while (itemData && itemData._type != 'server_group') { + i = pgBrowser.tree.next(i); + itemData = pgBrowser.tree.itemData(i); + } - // (Re)render the appropriate tab - $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { - switch ($(e.target).attr('aria-controls')) { - case "tab_server_activity": - pgAdmin.Dashboard.render_grid_data(div_server_activity); - break; + if (!itemData) { + return; + } - case "tab_server_locks": - pgAdmin.Dashboard.render_grid_data(div_server_locks); - break; + if (serverModule) { + serverModule.callbacks.show_obj_properties.apply( + serverModule, [{ + action: 'create', + }, i] + ); + } + } + }, - case "tab_server_prepared": - pgAdmin.Dashboard.render_grid_data(div_server_prepared); - break; + // Render a grid + render_grid: function(container, sid, did, url, columns) { + var Datum = Backbone.Model.extend({}); - case "tab_server_config": - pgAdmin.Dashboard.render_grid_data(div_server_config); - break; - } - }); + var path = url + sid; + if (did != -1) { + path += '/' + did; + } - // Handle button clicks - $("button").click(function(e){ - switch(this.id) { - case "btn_server_activity_refresh": - pgAdmin.Dashboard.render_grid_data(div_server_activity); - break; + var Data = Backbone.Collection.extend({ + model: Datum, + url: path, + mode: 'client', + }); + + var data = new Data(); + + // Set up the grid + var grid = new Backgrid.Grid({ + columns: columns, + collection: data, + className: 'backgrid table-bordered presentation table backgrid-striped', + }); + + // Render the grid + $(container).append(grid.render().el); + + // Initialize a client-side filter to filter on the client + // mode pageable collection's cache. + var filter = new Backgrid.Extension.ClientSideFilter({ + collection: data, + }); + + // Render the filter + $('#' + container.id + '_filter').before(filter.render().el); + + // Add some space to the filter and move it to the right + $(filter.el).css({ + float: 'right', + margin: '5px', + 'margin-right': '2px', + 'margin-top': '3px', + }); + + // Stash objects for future use + $(container).data('data', data); + $(container).data('grid', grid); + $(container).data('filter', filter); + }, - case "btn_server_locks_refresh": - pgAdmin.Dashboard.render_grid_data(div_server_locks); - break; + // Render the data in a grid + render_grid_data: function(container) { + var data = $(container).data('data'), + grid = $(container).data('grid'), + filter = $(container).data('filter'); - case "btn_server_prepared_refresh": - pgAdmin.Dashboard.render_grid_data(div_server_prepared); - break; + if (_.isUndefined(data)) { + return null; + } - case "btn_server_config_refresh": - pgAdmin.Dashboard.render_grid_data(div_server_config); - break; - } - }); + data.fetch({ + reset: true, + success: function() { + // If we're showing an error, remove it, and replace the grid & filter + if ($(container).hasClass('grid-error')) { + $(container).removeClass('grid-error'); + $(container).html(grid.render().el); + $(filter.el).show(); + } + // Re-apply search criteria + filter.search(); }, - - // Rock n' roll on the database dashboard - init_database_dashboard: function(sid, did, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { - var div_sessions = document.getElementById('graph-sessions'); - var div_tps = document.getElementById('graph-tps'); - var div_ti = document.getElementById('graph-ti'); - var div_to = document.getElementById('graph-to'); - var div_bio = document.getElementById('graph-bio'); - var div_database_activity = document.getElementById('database_activity'); - var div_database_locks = document.getElementById('database_locks'); - var div_database_prepared = document.getElementById('database_prepared'); - var dataset_sessions = []; - var data_sessions = []; - var dataset_tps = []; - var data_tps = []; - var dataset_ti = []; - var data_ti = []; - var dataset_to = []; - var data_to = []; - var dataset_bio = []; - var data_bio = []; - - var options_line = { - parseFloat: false, - xaxis: { - min: 100, - max: 0, - autoscale: 0 - }, - yaxis : { - autoscale: 1 - }, - legend : { - position : 'nw', - backgroundColor : '#D2E8FF' - } - } - - var database_activity_columns = [{ - name: "pid", - label: gettext('PID'), - editable: false, - cell: "string" - }, { - name: "usename", - label: gettext('User'), - editable: false, - cell: "string" - }, { - name: "application_name", - label: gettext('Application'), - editable: false, - cell: "string" - }, { - name: "client_addr", - label: gettext('Client'), - editable: false, - cell: "string" - }, { - name: "backend_start", - label: gettext('Backend start'), - editable: false, - cell: "string" - }, { - name: "state", - label: gettext('State'), - editable: false, - cell: "string" - }]; - - if (version < 90600) { - database_activity_columns = database_activity_columns.concat( - [{ - name: "waiting", - label: gettext('Waiting?'), - editable: false, - cell: "string" - }]); - } else { - database_activity_columns = database_activity_columns.concat( - [{ - name: "wait_event", - label: gettext('Wait Event'), - editable: false, - cell: "string" - },{ - name: "blocking_pids", - label: gettext('Blocking PIDs'), - editable: false, - cell: "string" - }]); + error: function(model, xhr) { + var err = $.parseJSON(xhr.responseText), + msg = err.errormsg, + cls; + // If we get a 428, it means the server isn't connected + if (xhr.status == 428) { + if (_.isUndefined(msg) || _.isNull(msg)) { + msg = gettext('Please connect to the selected server to view the table.'); } + cls = 'info'; + } else { + msg = gettext('An error occurred whilst rendering the table.'); + cls = 'danger'; + } - var newActiveQueryDetailsModel = new ActiveQueryDetailsModel(); - - var subNodeFieldsModel = Backform.generateViewSchema( - null, newActiveQueryDetailsModel, 'create', null, null, true - ); - - // Add version to each field - _.each(subNodeFieldsModel[0].fields, function(obj) { - obj['version'] = version; - }); - - - // Add cancel active query button - database_activity_columns.unshift({ - name: "pg-backform-expand", label: "", - cell: SessionDetailsCell, - cell_priority: -1, - postgres_version: version, - schema: subNodeFieldsModel - }); - - database_activity_columns.unshift({ - name: "pg-backform-delete", label: "", - cell: customDashboardActionCell, - cell_action: 'cancel', - editable: false, cell_priority: -1, - canDeleteRow: pgAdmin.Dashboard.can_take_action, - postgres_version: version - }); - database_activity_columns.unshift({ - name: "pg-backform-delete", label: "", - cell: customDashboardActionCell, - cell_action: 'terminate', - editable: false, cell_priority: -1, - canDeleteRow: pgAdmin.Dashboard.can_take_action, - postgres_version: version - }); - - var database_locks_columns = [{ - name: "pid", - label: gettext('PID'), - editable: false, - cell: "string" - }, { - name: "locktype", - label: gettext('Lock type'), - editable: false, - cell: "string" - }, { - name: "relation", - label: gettext('Target relation'), - editable: false, - cell: "string" - }, { - name: "page", - label: gettext('Page'), - editable: false, - cell: "string" - }, { - name: "tuple", - label: gettext('Tuple'), - editable: false, - cell: "string" - }, { - name: "virtualxid", - label: gettext('vXID (target)'), - editable: false, - cell: "string" - }, { - name: "transactionid", - label: gettext('XID (target)'), - editable: false, - cell: "string" - },{ - name: "classid", - label: gettext('Class'), - editable: false, - cell: "string" - },{ - name: "objid", - label: gettext('Object ID'), - editable: false, - cell: "string" - },{ - name: "virtualtransaction", - label: gettext('vXID (owner)'), - editable: false, - cell: "string" - },{ - name: "mode", - label: gettext('Mode'), - editable: false, - cell: "string" - },{ - name: "granted", - label: gettext('Granted?'), - editable: false, - cell: "string" - }]; - - var database_prepared_columns = [{ - name: "git", - label: gettext('Name'), - editable: false, - cell: "string" - }, { - name: "Owner", - label: gettext('Owner'), - editable: false, - cell: "string" - }, { - name: "transaction", - label: gettext('XID'), - editable: false, - cell: "string" - }, { - name: "prepared", - label: gettext('Prepared at'), - editable: false, - cell: "string" - }]; - - // Render the graphs - pgAdmin.Dashboard.render_chart( - div_sessions, data_sessions, dataset_sessions, sid, did, - url_for('dashboard.session_stats'), options_line, false, - session_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_tps, data_tps, dataset_tps, sid, did, - url_for('dashboard.tps_stats'), options_line, true, - tps_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_ti, data_ti, dataset_ti, sid, did, - url_for('dashboard.ti_stats'), options_line, true, - ti_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_to, data_to, dataset_to, sid, did, - url_for('dashboard.to_stats'), options_line, true, - to_stats_refresh - ); - pgAdmin.Dashboard.render_chart( - div_bio, data_bio, dataset_bio, sid, did, - url_for('dashboard.bio_stats'), options_line, true, - bio_stats_refresh - ); - - // To align subnode controls properly - $(div_database_activity).addClass('pg-el-container'); - $(div_database_activity).attr('el', 'sm'); - - // Render the tabs, but only get data for the activity tab for now - pgAdmin.Dashboard.render_grid( - div_database_activity, sid, did, url_for('dashboard.activity'), - database_activity_columns - ); - pgAdmin.Dashboard.render_grid( - div_database_locks, sid, did, url_for('dashboard.locks'), - database_locks_columns - ); - pgAdmin.Dashboard.render_grid( - div_database_prepared, sid, did, url_for('dashboard.prepared'), - database_prepared_columns - ); - - pgAdmin.Dashboard.render_grid_data(div_database_activity); - - // (Re)render the appropriate tab - $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { - switch ($(e.target).attr('aria-controls')) { - case "tab_database_activity": - pgAdmin.Dashboard.render_grid_data(div_database_activity); - break; + // Replace the content with the error, if not already present. Always update the message + if (!$(container).hasClass('grid-error')) { + $(filter.el).hide(); + $(container).addClass('grid-error'); + } - case "tab_database_locks": - pgAdmin.Dashboard.render_grid_data(div_database_locks); - break; + $(container).html( + '' + ); - case "tab_database_prepared": - pgAdmin.Dashboard.render_grid_data(div_database_prepared); - break; - } - }); + // Try again + setTimeout(function() { + pgAdmin.Dashboard.render_grid_data(container, data); + }, 5000); + }, + }); + }, - // Handle button clicks - $("button").click(function(e){ - switch(this.id) { - case "btn_database_activity_refresh": - pgAdmin.Dashboard.render_grid_data(div_database_activity); - break; + // Rock n' roll on the server dashboard + init_server_dashboard: function(sid, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { + var div_sessions = $('.dashboard-container').find('#graph-sessions')[0]; + var div_tps = $('.dashboard-container').find('#graph-tps')[0]; + var div_ti = $('.dashboard-container').find('#graph-ti')[0]; + var div_to = $('.dashboard-container').find('#graph-to')[0]; + var div_bio = $('.dashboard-container').find('#graph-bio')[0]; + var div_server_activity = $('.dashboard-container').find('#server_activity'); + var div_server_locks = $('.dashboard-container').find('#server_locks'); + var div_server_prepared = $('.dashboard-container').find('#server_prepared'); + var div_server_config = $('.dashboard-container').find('#server_config'); + var dataset_sessions = []; + var data_sessions = []; + var dataset_tps = []; + var data_tps = []; + var dataset_ti = []; + var data_ti = []; + var dataset_to = []; + var data_to = []; + var dataset_bio = []; + var data_bio = []; + + // Fake DB ID + var did = -1; + + var options_line = { + parseFloat: false, + xaxis: { + min: 100, + max: 0, + autoscale: 0, + }, + yaxis: { + autoscale: 1, + }, + legend: { + position: 'nw', + backgroundColor: '#D2E8FF', + }, + }; + + var server_activity_columns = [{ + name: 'pid', + label: gettext('PID'), + editable: false, + cell: 'string', + }, { + name: 'datname', + label: gettext('Database'), + editable: false, + cell: 'string', + }, { + name: 'usename', + label: gettext('User'), + editable: false, + cell: 'string', + }, { + name: 'application_name', + label: gettext('Application'), + editable: false, + cell: 'string', + }, { + name: 'client_addr', + label: gettext('Client'), + editable: false, + cell: 'string', + }, { + name: 'backend_start', + label: gettext('Backend start'), + editable: false, + cell: 'string', + }, { + name: 'state', + label: gettext('State'), + editable: false, + cell: 'string', + }]; + + if (version < 90600) { + server_activity_columns = server_activity_columns.concat( + [{ + name: 'waiting', + label: gettext('Waiting?'), + editable: false, + cell: 'string', + }]); + } else { + server_activity_columns = server_activity_columns.concat( + [{ + name: 'wait_event', + label: gettext('Wait Event'), + editable: false, + cell: 'string', + }, { + name: 'blocking_pids', + label: gettext('Blocking PIDs'), + editable: false, + cell: 'string', + }]); + } - case "btn_database_locks_refresh": - pgAdmin.Dashboard.render_grid_data(div_database_locks); - break; + var newActiveQueryDetailsModel = new ActiveQueryDetailsModel(); + + var subNodeFieldsModel = Backform.generateViewSchema( + null, newActiveQueryDetailsModel, 'create', null, null, true + ); + + // Add version to each field + _.each(subNodeFieldsModel[0].fields, function(obj) { + obj['version'] = version; + }); + + // Add cancel active query button + server_activity_columns.unshift({ + name: 'pg-backform-expand', + label: '', + cell: SessionDetailsCell, + cell_priority: -1, + postgres_version: version, + schema: subNodeFieldsModel, + }); + + // Add cancel active query button + server_activity_columns.unshift({ + name: 'pg-backform-delete', + label: '', + cell: customDashboardActionCell, + cell_action: 'cancel', + editable: false, + cell_priority: -1, + canDeleteRow: pgAdmin.Dashboard.can_take_action, + postgres_version: version, + }); + + server_activity_columns.unshift({ + name: 'pg-backform-delete', + label: '', + cell: customDashboardActionCell, + cell_action: 'terminate', + editable: false, + cell_priority: -1, + canDeleteRow: pgAdmin.Dashboard.can_take_action, + postgres_version: version, + }); + + var server_locks_columns = [{ + name: 'pid', + label: gettext('PID'), + editable: false, + cell: 'string', + }, { + name: 'datname', + label: gettext('Database'), + editable: false, + cell: 'string', + }, { + name: 'locktype', + label: gettext('Lock type'), + editable: false, + cell: 'string', + }, { + name: 'relation', + label: gettext('Target relation'), + editable: false, + cell: 'string', + }, { + name: 'page', + label: gettext('Page'), + editable: false, + cell: 'string', + }, { + name: 'tuple', + label: gettext('Tuple'), + editable: false, + cell: 'string', + }, { + name: 'virtualxid', + label: gettext('vXID (target)'), + editable: false, + cell: 'string', + }, { + name: 'transactionid', + label: gettext('XID (target)'), + editable: false, + cell: 'string', + }, { + name: 'classid', + label: gettext('Class'), + editable: false, + cell: 'string', + }, { + name: 'objid', + label: gettext('Object ID'), + editable: false, + cell: 'string', + }, { + name: 'virtualtransaction', + label: gettext('vXID (owner)'), + editable: false, + cell: 'string', + }, { + name: 'mode', + label: gettext('Mode'), + editable: false, + cell: 'string', + }, { + name: 'granted', + label: gettext('Granted?'), + editable: false, + cell: 'string', + }]; + + var server_prepared_columns = [{ + name: 'git', + label: gettext('Name'), + editable: false, + cell: 'string', + }, { + name: 'database', + label: gettext('Database'), + editable: false, + cell: 'string', + }, { + name: 'Owner', + label: gettext('Owner'), + editable: false, + cell: 'string', + }, { + name: 'transaction', + label: gettext('XID'), + editable: false, + cell: 'string', + }, { + name: 'prepared', + label: gettext('Prepared at'), + editable: false, + cell: 'string', + }]; + + var server_config_columns = [{ + name: 'name', + label: gettext('Name'), + editable: false, + cell: 'string', + }, { + name: 'category', + label: gettext('Category'), + editable: false, + cell: 'string', + }, { + name: 'setting', + label: gettext('Setting'), + editable: false, + cell: 'string', + }, { + name: 'unit', + label: gettext('Unit'), + editable: false, + cell: 'string', + }, { + name: 'short_desc', + label: gettext('Description'), + editable: false, + cell: 'string', + }]; + + // Render the graphs + pgAdmin.Dashboard.render_chart( + div_sessions, data_sessions, dataset_sessions, sid, did, + url_for('dashboard.session_stats'), options_line, false, + session_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_tps, data_tps, dataset_tps, sid, did, + url_for('dashboard.tps_stats'), options_line, true, + tps_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_ti, data_ti, dataset_ti, sid, did, + url_for('dashboard.ti_stats'), options_line, true, + ti_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_to, data_to, dataset_to, sid, did, + url_for('dashboard.to_stats'), options_line, true, + to_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_bio, data_bio, dataset_bio, sid, did, + url_for('dashboard.bio_stats'), options_line, true, + bio_stats_refresh + ); + + // To align subnode controls properly + $(div_server_activity).addClass('pg-el-container'); + $(div_server_activity).attr('el', 'sm'); + + // Render the tabs, but only get data for the activity tab for now + pgAdmin.Dashboard.render_grid( + div_server_activity, sid, did, + url_for('dashboard.activity'), server_activity_columns + ); + pgAdmin.Dashboard.render_grid( + div_server_locks, sid, did, url_for('dashboard.locks'), + server_locks_columns + ); + pgAdmin.Dashboard.render_grid( + div_server_prepared, sid, did, url_for('dashboard.prepared'), + server_prepared_columns + ); + pgAdmin.Dashboard.render_grid( + div_server_config, sid, did, url_for('dashboard.config'), + server_config_columns + ); + + pgAdmin.Dashboard.render_grid_data(div_server_activity); + + // (Re)render the appropriate tab + $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) { + switch ($(e.target).attr('aria-controls')) { + case 'tab_server_activity': + pgAdmin.Dashboard.render_grid_data(div_server_activity); + break; + + case 'tab_server_locks': + pgAdmin.Dashboard.render_grid_data(div_server_locks); + break; + + case 'tab_server_prepared': + pgAdmin.Dashboard.render_grid_data(div_server_prepared); + break; + + case 'tab_server_config': + pgAdmin.Dashboard.render_grid_data(div_server_config); + break; + } + }); + + // Handle button clicks + $('button').click(function() { + switch (this.id) { + case 'btn_server_activity_refresh': + pgAdmin.Dashboard.render_grid_data(div_server_activity); + break; + + case 'btn_server_locks_refresh': + pgAdmin.Dashboard.render_grid_data(div_server_locks); + break; + + case 'btn_server_prepared_refresh': + pgAdmin.Dashboard.render_grid_data(div_server_prepared); + break; + + case 'btn_server_config_refresh': + pgAdmin.Dashboard.render_grid_data(div_server_config); + break; + } + }); - case "btn_database_prepared_refresh": - pgAdmin.Dashboard.render_grid_data(div_database_prepared); - break; - } - }); + }, + // Rock n' roll on the database dashboard + init_database_dashboard: function(sid, did, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { + var div_sessions = document.getElementById('graph-sessions'); + var div_tps = document.getElementById('graph-tps'); + var div_ti = document.getElementById('graph-ti'); + var div_to = document.getElementById('graph-to'); + var div_bio = document.getElementById('graph-bio'); + var div_database_activity = document.getElementById('database_activity'); + var div_database_locks = document.getElementById('database_locks'); + var div_database_prepared = document.getElementById('database_prepared'); + var dataset_sessions = []; + var data_sessions = []; + var dataset_tps = []; + var data_tps = []; + var dataset_ti = []; + var data_ti = []; + var dataset_to = []; + var data_to = []; + var dataset_bio = []; + var data_bio = []; + + var options_line = { + parseFloat: false, + xaxis: { + min: 100, + max: 0, + autoscale: 0, }, - toggleVisibility: function(flag) { - dashboardVisible = flag; + yaxis: { + autoscale: 1, }, - can_take_action: function(m) { - // We will validate if user is allowed to cancel the active query - // If there is only one active session means it probably our main - // connection session - var active_sessions = m.collection.where({'state': 'active'}), - pg_version = this.get('postgres_version') || null, - cell_action = this.get('cell_action') || null, - is_cancel_session = cell_action === 'cancel', - txtAction = is_cancel_session ? gettext('cancel') : gettext('terminate'); - - // With PG10, We have background process showing on dashboard - // We will not allow user to cancel them as they will fail with error - // anyway, so better usability we will throw our on notification - - // Background processes do not have database field populated - if (pg_version && pg_version >= 100000 && !m.get('datname')) { - alertify.info( - gettext('You cannot ') + - txtAction + - gettext(' background worker processes.') - ); - return false; - // If it is the last active connection on maintenance db then error out - } else if (maintenance_database == m.get('datname') && - m.get('state') == 'active' && active_sessions.length == 1) { - alertify.error( - gettext('You are not allowed to ') + - txtAction + - gettext(' the main active session.') - ); - return false; - } else if(is_cancel_session && m.get('state') == 'idle') { - // If this session is already idle then do nothing - alertify.info( - gettext('The session is already in idle state.') - ); - return false; - } else if(is_super_user) { - // Super user can do anything - return true; - } else if (current_user && current_user == m.get('usename')) { - // Non-super user can cancel only their active queries - return true; - } else { - // Do not allow to cancel someone else session to non-super user - alertify.error( - gettext('Superuser privileges are required to ') + - txtAction + - gettext(' another users query.') - ); - return false; - } + legend: { + position: 'nw', + backgroundColor: '#D2E8FF', + }, + }; + + var database_activity_columns = [{ + name: 'pid', + label: gettext('PID'), + editable: false, + cell: 'string', + }, { + name: 'usename', + label: gettext('User'), + editable: false, + cell: 'string', + }, { + name: 'application_name', + label: gettext('Application'), + editable: false, + cell: 'string', + }, { + name: 'client_addr', + label: gettext('Client'), + editable: false, + cell: 'string', + }, { + name: 'backend_start', + label: gettext('Backend start'), + editable: false, + cell: 'string', + }, { + name: 'state', + label: gettext('State'), + editable: false, + cell: 'string', + }]; + + if (version < 90600) { + database_activity_columns = database_activity_columns.concat( + [{ + name: 'waiting', + label: gettext('Waiting?'), + editable: false, + cell: 'string', + }]); + } else { + database_activity_columns = database_activity_columns.concat( + [{ + name: 'wait_event', + label: gettext('Wait Event'), + editable: false, + cell: 'string', + }, { + name: 'blocking_pids', + label: gettext('Blocking PIDs'), + editable: false, + cell: 'string', + }]); + } + + var newActiveQueryDetailsModel = new ActiveQueryDetailsModel(); + + var subNodeFieldsModel = Backform.generateViewSchema( + null, newActiveQueryDetailsModel, 'create', null, null, true + ); + + // Add version to each field + _.each(subNodeFieldsModel[0].fields, function(obj) { + obj['version'] = version; + }); + + + // Add cancel active query button + database_activity_columns.unshift({ + name: 'pg-backform-expand', + label: '', + cell: SessionDetailsCell, + cell_priority: -1, + postgres_version: version, + schema: subNodeFieldsModel, + }); + + database_activity_columns.unshift({ + name: 'pg-backform-delete', + label: '', + cell: customDashboardActionCell, + cell_action: 'cancel', + editable: false, + cell_priority: -1, + canDeleteRow: pgAdmin.Dashboard.can_take_action, + postgres_version: version, + }); + database_activity_columns.unshift({ + name: 'pg-backform-delete', + label: '', + cell: customDashboardActionCell, + cell_action: 'terminate', + editable: false, + cell_priority: -1, + canDeleteRow: pgAdmin.Dashboard.can_take_action, + postgres_version: version, + }); + + var database_locks_columns = [{ + name: 'pid', + label: gettext('PID'), + editable: false, + cell: 'string', + }, { + name: 'locktype', + label: gettext('Lock type'), + editable: false, + cell: 'string', + }, { + name: 'relation', + label: gettext('Target relation'), + editable: false, + cell: 'string', + }, { + name: 'page', + label: gettext('Page'), + editable: false, + cell: 'string', + }, { + name: 'tuple', + label: gettext('Tuple'), + editable: false, + cell: 'string', + }, { + name: 'virtualxid', + label: gettext('vXID (target)'), + editable: false, + cell: 'string', + }, { + name: 'transactionid', + label: gettext('XID (target)'), + editable: false, + cell: 'string', + }, { + name: 'classid', + label: gettext('Class'), + editable: false, + cell: 'string', + }, { + name: 'objid', + label: gettext('Object ID'), + editable: false, + cell: 'string', + }, { + name: 'virtualtransaction', + label: gettext('vXID (owner)'), + editable: false, + cell: 'string', + }, { + name: 'mode', + label: gettext('Mode'), + editable: false, + cell: 'string', + }, { + name: 'granted', + label: gettext('Granted?'), + editable: false, + cell: 'string', + }]; + + var database_prepared_columns = [{ + name: 'git', + label: gettext('Name'), + editable: false, + cell: 'string', + }, { + name: 'Owner', + label: gettext('Owner'), + editable: false, + cell: 'string', + }, { + name: 'transaction', + label: gettext('XID'), + editable: false, + cell: 'string', + }, { + name: 'prepared', + label: gettext('Prepared at'), + editable: false, + cell: 'string', + }]; + + // Render the graphs + pgAdmin.Dashboard.render_chart( + div_sessions, data_sessions, dataset_sessions, sid, did, + url_for('dashboard.session_stats'), options_line, false, + session_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_tps, data_tps, dataset_tps, sid, did, + url_for('dashboard.tps_stats'), options_line, true, + tps_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_ti, data_ti, dataset_ti, sid, did, + url_for('dashboard.ti_stats'), options_line, true, + ti_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_to, data_to, dataset_to, sid, did, + url_for('dashboard.to_stats'), options_line, true, + to_stats_refresh + ); + pgAdmin.Dashboard.render_chart( + div_bio, data_bio, dataset_bio, sid, did, + url_for('dashboard.bio_stats'), options_line, true, + bio_stats_refresh + ); + + // To align subnode controls properly + $(div_database_activity).addClass('pg-el-container'); + $(div_database_activity).attr('el', 'sm'); + + // Render the tabs, but only get data for the activity tab for now + pgAdmin.Dashboard.render_grid( + div_database_activity, sid, did, url_for('dashboard.activity'), + database_activity_columns + ); + pgAdmin.Dashboard.render_grid( + div_database_locks, sid, did, url_for('dashboard.locks'), + database_locks_columns + ); + pgAdmin.Dashboard.render_grid( + div_database_prepared, sid, did, url_for('dashboard.prepared'), + database_prepared_columns + ); + + pgAdmin.Dashboard.render_grid_data(div_database_activity); + + // (Re)render the appropriate tab + $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) { + switch ($(e.target).attr('aria-controls')) { + case 'tab_database_activity': + pgAdmin.Dashboard.render_grid_data(div_database_activity); + break; + + case 'tab_database_locks': + pgAdmin.Dashboard.render_grid_data(div_database_locks); + break; + + case 'tab_database_prepared': + pgAdmin.Dashboard.render_grid_data(div_database_prepared); + break; } + }); + + // Handle button clicks + $('button').click(function() { + switch (this.id) { + case 'btn_database_activity_refresh': + pgAdmin.Dashboard.render_grid_data(div_database_activity); + break; + + case 'btn_database_locks_refresh': + pgAdmin.Dashboard.render_grid_data(div_database_locks); + break; + + case 'btn_database_prepared_refresh': + pgAdmin.Dashboard.render_grid_data(div_database_prepared); + break; + } + }); + + }, + toggleVisibility: function(flag) { + dashboardVisible = flag; + }, + can_take_action: function(m) { + // We will validate if user is allowed to cancel the active query + // If there is only one active session means it probably our main + // connection session + var active_sessions = m.collection.where({ + 'state': 'active', + }), + pg_version = this.get('postgres_version') || null, + cell_action = this.get('cell_action') || null, + is_cancel_session = cell_action === 'cancel', + txtAction = is_cancel_session ? gettext('cancel') : gettext('terminate'); + + // With PG10, We have background process showing on dashboard + // We will not allow user to cancel them as they will fail with error + // anyway, so better usability we will throw our on notification + + // Background processes do not have database field populated + if (pg_version && pg_version >= 100000 && !m.get('datname')) { + Alertify.info( + gettext('You cannot ') + + txtAction + + gettext(' background worker processes.') + ); + return false; + // If it is the last active connection on maintenance db then error out + } else if (maintenance_database == m.get('datname') && + m.get('state') == 'active' && active_sessions.length == 1) { + Alertify.error( + gettext('You are not allowed to ') + + txtAction + + gettext(' the main active session.') + ); + return false; + } else if (is_cancel_session && m.get('state') == 'idle') { + // If this session is already idle then do nothing + Alertify.info( + gettext('The session is already in idle state.') + ); + return false; + } else if (is_super_user) { + // Super user can do anything + return true; + } else if (current_user && current_user == m.get('usename')) { + // Non-super user can cancel only their active queries + return true; + } else { + // Do not allow to cancel someone else session to non-super user + Alertify.error( + gettext('Superuser privileges are required to ') + + txtAction + + gettext(' another users query.') + ); + return false; + } + }, }; return pgAdmin.Dashboard; diff --git a/web/pgadmin/misc/bgprocess/static/js/bgprocess.js b/web/pgadmin/misc/bgprocess/static/js/bgprocess.js index be4ac152..5e305908 100644 --- a/web/pgadmin/misc/bgprocess/static/js/bgprocess.js +++ b/web/pgadmin/misc/bgprocess/static/js/bgprocess.js @@ -1,9 +1,8 @@ define('misc.bgprocess', [ 'sources/pgadmin', 'sources/gettext', 'sources/url_for', 'underscore', 'underscore.string', 'jquery', 'pgadmin.browser', 'alertify', - 'pgadmin.browser.messages' ], function( - pgAdmin, gettext, url_for, _, S, $, pgBrowser, alertify, pgMessages + pgAdmin, gettext, url_for, _, S, $, pgBrowser, Alertify ) { pgBrowser.BackgroundProcessObsorver = pgBrowser.BackgroundProcessObsorver || {}; @@ -12,6 +11,8 @@ define('misc.bgprocess', [ return pgBrowser.BackgroundProcessObsorver; } + var wcDocker = window.wcDocker; + var BGProcess = function(info, notify) { var self = this; setTimeout( @@ -45,7 +46,9 @@ define('misc.bgprocess', [ notifier: null, container: null, panel: null, - logs: $('' + - '' + fm_filename + - '
'; - } - if (props.Width && props.Width != '') { - result += ''; - } - if (props.Size && props.Size != '') { - result += ''; - } - if (props['Date Created'] && props['Date Created'] != '') { - result += ''; - } - if (props['Date Modified'] && props['Date Modified'] != '') { - result += ''; - } - result += ''; - }); + result += '' + + '' + fm_filename + + '
'; + } + if (props.Width && props.Width != '') { + result += ''; + } + if (props.Size && props.Size != '') { + result += ''; + } + if (props['Date Created'] && props['Date Created'] != '') { + result += ''; + } + if (props['Date Modified'] && props['Date Modified'] != '') { + result += ''; + } + result += '| '; - result += '' + lg.name +' | '; - result += '' + lg.size + ' | '; - result += '' + lg.modified + ' |
|---|
| '; + result += '' + lg.name + ' | '; + result += '' + lg.size + ' | '; + result += '' + lg.modified + ' | |||||||
|---|---|---|---|---|---|---|---|---|---|
| '; - if ((data[key]).Protected == 1) { - result += - ''; - } - if (!has_capability(data[key], 'rename')) { - result += '' + - fm_filename + ' | '; - } else { - result += '' + - props.Size + ' | '; - } else { - result += ''; - } + result += ' | '; + if ((data[key]).Protected == 1) { + result += + ''; + } + if (!has_capability(data[key], 'rename')) { + result += '' + + fm_filename + ' | '; + } else { + result += '' + + props.Size + ' | '; + } else { + result += ''; + } - if (props['Date Modified'] && props['Date Modified'] != '') { - result += ' | ' + props['Date Modified'] + ' | '; - } else { - result += ''; - } + if (props['Date Modified'] && props['Date Modified'] != '') { + result += ' | ' + props['Date Modified'] + ' | '; + } else { + result += ''; + } - result += ' |
| ' + - lg.name + ' | ' + lg.size +
+ if ($('.fileinfo').data('view') == 'grid') {
+ result += '
' + key + ' | ' + value + ' | ' + key + ' | ' + value + ' | " +
- gettext('Category is not selected.') +
- " "
- );
-
- // Create the aci-tree for listing the modules and categories of
- // it.
- jTree = $container.find('.preferences_tree');
- jTree.on('acitree', treeEventHandler);
-
- jTree.aciTree({
- selectable: true,
- expand: true,
- ajax: {
- url: url_for('preferences.index')
- }
- });
+ // Dialog property
+ return {
+ main: function() {
+
+ // Remove the existing content first.
+ dialogContentCleanup();
+
+ $container.append(
+ ''
+ ).append(
+ '' +
+ gettext('Category is not selected.') +
+ ' '
+ );
+
+ // Create the aci-tree for listing the modules and categories of
+ // it.
+ jTree = $container.find('.preferences_tree');
+ jTree.on('acitree', treeEventHandler);
+
+ jTree.aciTree({
+ selectable: true,
+ expand: true,
+ ajax: {
+ url: url_for('preferences.index'),
+ },
+ });
- this.show();
- },
- setup: function() {
- return {
- buttons:[{
- text: '', key: 112,
- className: 'btn btn-default pull-left fa fa-lg fa-question',
- attrs:{
- name:'dialog_help', type:'button',
- label: gettext('Preferences'),
- url: url_for(
- 'help.static', {'filename': 'preferences.html'}
- )
- }
- },{
- text: gettext('OK'), key: 13, className: "btn btn-primary fa fa-lg fa-save pg-alertify-button"
- },{
- text: gettext('Cancel'), key: 27, className: "btn btn-danger fa fa-lg fa-times pg-alertify-button"
- }],
- focus: { element: 0 },
- options: {
- padding: !1,
- overflow: !1,
- title: gettext('Preferences'),
- closableByDimmer: false,
- modal:false,
- pinnable: false
- }
- };
- },
- callback: function(e) {
- if (e.button.element.name == "dialog_help") {
- e.cancel = true;
- pgBrowser.showHelp(e.button.element.name, e.button.element.getAttribute('url'),
- null, null, e.button.element.getAttribute('label'));
- return;
- }
-
- if (e.button.text == gettext('OK')){
- preferences.updateAll();
- // Refresh preferences cache
- setTimeout(pgBrowser.cache_preferences(), 2000);
- }
- },
- build: function() {
- this.elements.content.appendChild($container.get(0));
- alertify.pgDialogBuild.apply(this)
- },
- hooks: {
- onshow: function() {
- $(this.elements.body).addClass('pgadmin-preference-body');
- }
+ this.show();
+ },
+ setup: function() {
+ return {
+ buttons: [{
+ text: '',
+ key: 112,
+ className: 'btn btn-default pull-left fa fa-lg fa-question',
+ attrs: {
+ name: 'dialog_help',
+ type: 'button',
+ label: gettext('Preferences'),
+ url: url_for(
+ 'help.static', {
+ 'filename': 'preferences.html',
+ }
+ ),
+ },
+ }, {
+ text: gettext('OK'),
+ key: 13,
+ className: 'btn btn-primary fa fa-lg fa-save pg-alertify-button',
+ }, {
+ text: gettext('Cancel'),
+ key: 27,
+ className: 'btn btn-danger fa fa-lg fa-times pg-alertify-button',
+ }],
+ focus: {
+ element: 0,
+ },
+ options: {
+ padding: !1,
+ overflow: !1,
+ title: gettext('Preferences'),
+ closableByDimmer: false,
+ modal: false,
+ pinnable: false,
+ },
+ };
+ },
+ callback: function(e) {
+ if (e.button.element.name == 'dialog_help') {
+ e.cancel = true;
+ pgBrowser.showHelp(e.button.element.name, e.button.element.getAttribute('url'),
+ null, null, e.button.element.getAttribute('label'));
+ return;
}
- };
- });
-
- },
- show: function() {
- alertify.preferencesDlg(true).resizeTo('60%', '60%');
- }
- };
- return pgAdmin.Preferences;
- });
+ if (e.button.text == gettext('OK')) {
+ preferences.updateAll();
+ // Refresh preferences cache
+ setTimeout(pgBrowser.cache_preferences(), 2000);
+ }
+ },
+ build: function() {
+ this.elements.content.appendChild($container.get(0));
+ Alertify.pgDialogBuild.apply(this);
+ },
+ hooks: {
+ onshow: function() {
+ $(this.elements.body).addClass('pgadmin-preference-body');
+ },
+ },
+ };
+ });
+
+ },
+ show: function() {
+ Alertify.preferencesDlg(true).resizeTo('60%', '60%');
+ },
+ };
+
+ return pgAdmin.Preferences;
+});
diff --git a/web/pgadmin/settings/static/js/settings.js b/web/pgadmin/settings/static/js/settings.js
index 2194955c..634368cf 100644
--- a/web/pgadmin/settings/static/js/settings.js
+++ b/web/pgadmin/settings/static/js/settings.js
@@ -1,59 +1,59 @@
-define('pgadmin.settings',
- [
- 'jquery', 'alertify', 'sources/pgadmin', 'underscore', 'backform',
- 'sources/gettext', 'sources/url_for', 'pgadmin.backform'
- ],
+define('pgadmin.settings', [
+ 'jquery', 'pgadmin.alertifyjs', 'sources/pgadmin',
+ 'sources/gettext', 'sources/url_for', 'pgadmin.backform',
+], function($, Alertify, pgAdmin, gettext, url_for) {
+
// This defines the Preference/Options Dialog for pgAdmin IV.
- function($, alertify, pgAdmin, _, Backform, gettext, url_for) {
- pgAdmin = pgAdmin || window.pgAdmin || {};
+ pgAdmin = pgAdmin || window.pgAdmin || {};
- /*
- * Hmm... this module is already been initialized, we can refer to the old
- * object from here.
- */
- if (pgAdmin.Settings)
- return pgAdmin.Settings;
+ /*
+ * Hmm... this module is already been initialized, we can refer to the old
+ * object from here.
+ */
+ if (pgAdmin.Settings)
+ return pgAdmin.Settings;
- pgAdmin.Settings = {
- init: function() {
- if (this.initialized)
- return;
+ pgAdmin.Settings = {
+ init: function() {
+ if (this.initialized)
+ return;
- this.initialized = true;
- },
- // We will force unload method to not to save current layout
- // and reload the window
- show: function() {
- var obj = this;
- alertify.confirm(gettext('Reset layout'),
- gettext('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.'),
- function() {
- var reloadingIndicator = $('');
- $('body').append(reloadingIndicator);
- // Delete the record from database as well, then only reload page
- $.ajax({
- url: url_for('settings.reset_layout'),
- type: 'DELETE',
- async: false,
- success: function() {
- // Prevent saving layout on server for next page reload.
- $(window).unbind('unload');
- window.onbeforeunload = null;
- // Now reload page
- location.reload(true);
- },
- error: function() {
- console.log('Something went wrong on server while resetting layout');
- }
- });
+ this.initialized = true;
+ },
+ // We will force unload method to not to save current layout
+ // and reload the window
+ show: function() {
+ Alertify.confirm(gettext('Reset layout'),
+ gettext('Are you sure you want to reset the current layout? This will cause the application to reload and any un-saved data will be lost.'),
+ function() {
+ var reloadingIndicator = $('');
+ $('body').append(reloadingIndicator);
+ // Delete the record from database as well, then only reload page
+ $.ajax({
+ url: url_for('settings.reset_layout'),
+ type: 'DELETE',
+ async: false,
+ success: function() {
+ // Prevent saving layout on server for next page reload.
+ $(window).unbind('unload');
+ window.onbeforeunload = null;
+ // Now reload page
+ location.reload(true);
+ },
+ error: function() {
+ console.warn(
+ 'Something went wrong on server while resetting layout.'
+ );
+ },
+ });
- },
- function() {
- // Do nothing as user canceled the operation.
- }
- );
- }
- };
+ },
+ function() {
+ // Do nothing as user canceled the operation.
+ }
+ );
+ },
+ };
- return pgAdmin.Settings;
- });
+ return pgAdmin.Settings;
+});
|
|---|